package com.sevattal.service.leaves.controller;


import com.sevattal.common.base.result.R;
import com.sevattal.service.leaves.entity.vo.AuditOrderVo;
import com.sevattal.service.leaves.entity.vo.PurchaseArrivalOrderVo;
import com.sevattal.service.leaves.service.PurchaseArrivalOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  采购到货到货主表 前端控制器
 * </p>
 *
 * @author Sevattal
 * @since 2021-08-28
 */
@Api(tags = "到货单管理")
@RestController
@RequestMapping("/admin/leaves/purchase-arrival-order")
public class PurchaseArrivalOrderController {

    @Autowired
    private PurchaseArrivalOrderService purchaseArrivalOrderService;


    @ApiOperation("新建采购到货单")
    @PostMapping("createPurchaseArrivalOrder")
    public R createPurchaseArrivalOrder(@ApiParam(value = "采购到货单对象",required = true) @RequestBody PurchaseArrivalOrderVo PurchaseArrivalOrderVo){
        boolean result = purchaseArrivalOrderService.createPurchaseArrivalOrder(PurchaseArrivalOrderVo);
        if (result) {
            return R.ok().message("创建成功");
        }else{
            return R.error().message("创建失败");
        }
    }

    @ApiOperation("修改采购到货单")
    @PutMapping("updatePurchaseArrivalOrder")
    public R updatePurchaseArrivalOrder(@ApiParam(value = "采购到货到货单对象",required = true) @RequestBody PurchaseArrivalOrderVo PurchaseArrivalOrderVo) {
        boolean result = purchaseArrivalOrderService.updatePurchaseArrivalOrder(PurchaseArrivalOrderVo);
        if (result) {
            return R.ok().message("修改成功");
        }else{
            return R.error().message("修改失败");
        }
    }

    @ApiOperation("删除采购到货单")
    @DeleteMapping("deletePurchaseArrivalOrder/{id}")
    public R deletePurchaseArrivalOrder(@ApiParam(value = "采购到货单ID",required = true) @PathVariable String id) {
        boolean result = purchaseArrivalOrderService.deletePurchaseArrivalOrder(id);
        if (result) {
            return R.ok().message("删除成功");
        }else{
            return R.error().message("删除失败");
        }
    }


    @ApiOperation("获取采购到货信息")
    @PostMapping("getPurchaseArrivalOrderList")
    public R getPurchaseArrivalOrderList(@ApiParam(value = "采购到货单对象",required =  true)  @RequestBody PurchaseArrivalOrderVo PurchaseArrivalOrderVo){
        List<PurchaseArrivalOrderVo> purchaseArrivalOrderList = purchaseArrivalOrderService.getPurchaseArrivalOrderList(PurchaseArrivalOrderVo);
        return R.ok().data("purchaseArrivalOrderList",purchaseArrivalOrderList);
    }

    @ApiOperation("确认到货")
    @PostMapping("confirmOrder/{id}")
    public R confirmOrder(@ApiParam(value = "采购到货单ID",required = true) @PathVariable String id) {
        boolean result = purchaseArrivalOrderService.confirmOrder(id);
        if (result) {
            return R.ok().message("删除成功");
        }else{
            return R.error().message("删除失败");
        }
    }


}

